#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by PyCharm.
# @Project: Code_Clone_Detection_Educoder
# @File: operate_task_status.py
# @Description: 
# @Time: 2018/12/17 21:14
# @Author: ljz

from CCDetector.utils import mysql_pool

mysql_operator = mysql_pool.MysqlPool()


def set_is_running(query_id):
    mysql_operator.insert("""
    insert into educoder_code_clone.status (query_id, is_completed) values ('{}', '{}')
    """.format(query_id, 0))


def set_is_completed(query_id):
    mysql_operator.update("""
    update educoder_code_clone.status set is_completed=1 where query_id='{}'
    """.format(query_id))


def check_is_completed(query_id):
    result = mysql_operator.select_one("""
    select is_completed from educoder_code_clone.status where query_id='{}'
    """.format(query_id))
    if result is None:
        return 'no task'
    elif result[0] == 1:
        return 'completed'
    else:
        return 'not completed'
